from setuptools import setup, find_packages
from pathlib import Path
import os

def create_init_files():
    """自动创建 __init__.py"""
    root = Path('typlot')
    if not root.exists():
        return
    
    # 在这里设置肯定不是想要的文件夹
    exclude = {'__pycache__', '.ipynb_checkpoints', 'logs', 'lsf','model',
               'checkpoints', 'outputs', 'data', '.vscode', '.conda'}
    
    created = []
    
    for dirpath, dirnames, filenames in os.walk(root):
        dirnames[:] = [d for d in dirnames if d not in exclude]
        
        py_files = [f for f in filenames if f.endswith('.py') and f != '__init__.py']
        
        if py_files:
            init_file = Path(dirpath) / '__init__.py'
            if not init_file.exists():
                init_file.write_text('# Auto-generated\n')
                created.append(init_file)
    
    if created:
        print(f"✓ 创建了 {len(created)} 个 __init__.py")
        for f in created:
            print(f"  {f}")

# ⭐⭐⭐ 关键：在 setup() 之前运行, 给包含.py文件的文件夹都创建__init__ ⭐⭐⭐

print("="*60)
print("检查并创建 __init__.py")
print("="*60)
create_init_files()


# 只有包含__init__.py的文件夹才会被认为是一个包的目录。
print("\n查找包...")
packages = find_packages()
print(f"找到 {len(packages)} 个包:")
for pkg in sorted(packages):
    print(f"  {pkg}")

print("\n开始安装...\n")
setup(
    name="typlot",
    version="0.1.0",
    packages=packages,
    python_requires='>=3.9',
)